using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSYSBADEF
    {
        public DataRow Convert2SYSBADEF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySYSBADEF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SYBMANDANT"] = " ".PadRight(2 ); 
         dwReturn["SYBPROG"] = " ".PadRight(8 ); 
         dwReturn["SYBSTAKZ"] = " ".PadRight(1 ); 
         dwReturn["SYBBEZ"] = " ".PadRight(40 ); 
         dwReturn["SYBAPROG"] = " ".PadRight(8 ); 
         dwReturn["SYBFPROG1"] = " ".PadRight(8 ); 
         dwReturn["SYBFPROG2"] = " ".PadRight(8 ); 
         dwReturn["SYBFPROG3"] = " ".PadRight(8 ); 
         dwReturn["SYBFPROG4"] = " ".PadRight(8 ); 
         dwReturn["SYBFPROG5"] = " ".PadRight(8 ); 
         dwReturn["SYBFORM"] = " ".PadRight(8 ); 
         dwReturn["SYBDBRT"] = " ".PadRight(0 ); 
         dwReturn["SYBDHOE"] = " ".PadRight(0 ); 
         dwReturn["SYBKOP"] = " ".PadRight(0 ); 
         dwReturn["SYBDECKBL"] = " ".PadRight(0 ); 
         dwReturn["SYBNOPRINT"] = " ".PadRight(1 ); 
         dwReturn["SYBSUBSYS"] = " ".PadRight(10 ); 
         dwReturn["SYBSPAETER"] = " ".PadRight(1 ); 
         dwReturn["SYBSFKT"] = " ".PadRight(1 ); 
         dwReturn["SYBUSERPRG"] = " ".PadRight(1 ); 
         dwReturn["SYBSTD"] = " ".PadRight(1 ); 
         dwReturn["SYBBPROG"] = " ".PadRight(8 ); 
         dwReturn["SYBTYP"] = " ".PadRight(1 ); 
         dwReturn["SYBKL1"] = " ".PadRight(2 ); 
         dwReturn["SYBKL2"] = " ".PadRight(2 ); 
         dwReturn["SYBKL3"] = " ".PadRight(2 ); 
         dwReturn["SYBANSTOSS1"] = " ".PadRight(8 ); 
         dwReturn["SYBANSTOSS2"] = " ".PadRight(8 ); 
         dwReturn["SYBANSTOSS3"] = " ".PadRight(8 ); 
         dwReturn["SYBANSTOSS4"] = " ".PadRight(8 ); 
         dwReturn["SYBANSTOSS5"] = " ".PadRight(8 ); 
         dwReturn["SYBANSTOSS6"] = " ".PadRight(8 ); 
         dwReturn["SYBANSTOSS7"] = " ".PadRight(8 ); 
         dwReturn["SYBSA"] = " ".PadRight(4 ); 
         dwReturn["SYBUKGRD"] = " ".PadRight(4 ); 
         dwReturn["SYBLEITWEG"] = " ".PadRight(10 ); 
         dwReturn["SYBBEM"] = " ".PadRight(60 ); 
         dwReturn["SYBSANR"] = " ".PadRight(2 ); 
         dwReturn["SYBCMD"] = " ".PadRight(50 ); 
         dwReturn["SYBFILLER"] = " ".PadRight(93 ); 
         dwReturn["SYBAENZL"] = " ".PadRight(0 ); 
         dwReturn["SYBAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["SYBAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["SYBNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["SYBNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSYSBADEF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSYSBADEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySYSBADEF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSYSBADEF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSYSBADEF(dwLocal, ITXDBVERSION);
            }
            UpdateSYSBADEF(dwLocal);
        }
        public void InsertSYSBADEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO SYSBADEF(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySYSBADEF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SYSBADEF WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM SYSBADEF  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "SYSBADEF";
            Return = Result;
            return Return;
        }
        public void DeleteSYSBADEF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM SYSBADEF   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSYSBADEF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE SYSBADEF SET "
                    +"SYBMANDANT= :SYBMANDANT,"
                    +"SYBPROG= :SYBPROG,"
                    +"SYBSTAKZ= :SYBSTAKZ,"
                    +"SYBBEZ= :SYBBEZ,"
                    +"SYBAPROG= :SYBAPROG,"
                    +"SYBFPROG1= :SYBFPROG1,"
                    +"SYBFPROG2= :SYBFPROG2,"
                    +"SYBFPROG3= :SYBFPROG3,"
                    +"SYBFPROG4= :SYBFPROG4,"
                    +"SYBFPROG5= :SYBFPROG5,"
                    +"SYBFORM= :SYBFORM,"
                    +"SYBDBRT= :SYBDBRT,"
                    +"SYBDHOE= :SYBDHOE,"
                    +"SYBKOP= :SYBKOP,"
                    +"SYBDECKBL= :SYBDECKBL,"
                    +"SYBNOPRINT= :SYBNOPRINT,"
                    +"SYBSUBSYS= :SYBSUBSYS,"
                    +"SYBSPAETER= :SYBSPAETER,"
                    +"SYBSFKT= :SYBSFKT,"
                    +"SYBUSERPRG= :SYBUSERPRG,"
                    +"SYBSTD= :SYBSTD,"
                    +"SYBBPROG= :SYBBPROG,"
                    +"SYBTYP= :SYBTYP,"
                    +"SYBKL1= :SYBKL1,"
                    +"SYBKL2= :SYBKL2,"
                    +"SYBKL3= :SYBKL3,"
                    +"SYBANSTOSS1= :SYBANSTOSS1,"
                    +"SYBANSTOSS2= :SYBANSTOSS2,"
                    +"SYBANSTOSS3= :SYBANSTOSS3,"
                    +"SYBANSTOSS4= :SYBANSTOSS4,"
                    +"SYBANSTOSS5= :SYBANSTOSS5,"
                    +"SYBANSTOSS6= :SYBANSTOSS6,"
                    +"SYBANSTOSS7= :SYBANSTOSS7,"
                    +"SYBSA= :SYBSA,"
                    +"SYBUKGRD= :SYBUKGRD,"
                    +"SYBLEITWEG= :SYBLEITWEG,"
                    +"SYBBEM= :SYBBEM,"
                    +"SYBSANR= :SYBSANR,"
                    +"SYBCMD= :SYBCMD,"
                    +"SYBFILLER= :SYBFILLER,"
                    +"SYBAENZL= :SYBAENZL,"
                    +"SYBAENDBEN= :SYBAENDBEN,"
                    +"SYBAENDDAT= :SYBAENDDAT,"
                    +"SYBNEUBEN= :SYBNEUBEN,"
                    +"SYBNEUDAT= :SYBNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SYBMANDANT", OracleType.NVarChar).Value = dwData["SYBMANDANT"].ToString(); 
          or1.Parameters.Add("SYBPROG", OracleType.NVarChar).Value = dwData["SYBPROG"].ToString(); 
          or1.Parameters.Add("SYBSTAKZ", OracleType.NVarChar).Value = dwData["SYBSTAKZ"].ToString(); 
          or1.Parameters.Add("SYBBEZ", OracleType.NVarChar).Value = dwData["SYBBEZ"].ToString(); 
          or1.Parameters.Add("SYBAPROG", OracleType.NVarChar).Value = dwData["SYBAPROG"].ToString(); 
          or1.Parameters.Add("SYBFPROG1", OracleType.NVarChar).Value = dwData["SYBFPROG1"].ToString(); 
          or1.Parameters.Add("SYBFPROG2", OracleType.NVarChar).Value = dwData["SYBFPROG2"].ToString(); 
          or1.Parameters.Add("SYBFPROG3", OracleType.NVarChar).Value = dwData["SYBFPROG3"].ToString(); 
          or1.Parameters.Add("SYBFPROG4", OracleType.NVarChar).Value = dwData["SYBFPROG4"].ToString(); 
          or1.Parameters.Add("SYBFPROG5", OracleType.NVarChar).Value = dwData["SYBFPROG5"].ToString(); 
          or1.Parameters.Add("SYBFORM", OracleType.NVarChar).Value = dwData["SYBFORM"].ToString(); 
          or1.Parameters.Add("SYBDBRT", OracleType.NVarChar).Value = dwData["SYBDBRT"].ToString(); 
          or1.Parameters.Add("SYBDHOE", OracleType.NVarChar).Value = dwData["SYBDHOE"].ToString(); 
          or1.Parameters.Add("SYBKOP", OracleType.NVarChar).Value = dwData["SYBKOP"].ToString(); 
          or1.Parameters.Add("SYBDECKBL", OracleType.NVarChar).Value = dwData["SYBDECKBL"].ToString(); 
          or1.Parameters.Add("SYBNOPRINT", OracleType.NVarChar).Value = dwData["SYBNOPRINT"].ToString(); 
          or1.Parameters.Add("SYBSUBSYS", OracleType.NVarChar).Value = dwData["SYBSUBSYS"].ToString(); 
          or1.Parameters.Add("SYBSPAETER", OracleType.NVarChar).Value = dwData["SYBSPAETER"].ToString(); 
          or1.Parameters.Add("SYBSFKT", OracleType.NVarChar).Value = dwData["SYBSFKT"].ToString(); 
          or1.Parameters.Add("SYBUSERPRG", OracleType.NVarChar).Value = dwData["SYBUSERPRG"].ToString(); 
          or1.Parameters.Add("SYBSTD", OracleType.NVarChar).Value = dwData["SYBSTD"].ToString(); 
          or1.Parameters.Add("SYBBPROG", OracleType.NVarChar).Value = dwData["SYBBPROG"].ToString(); 
          or1.Parameters.Add("SYBTYP", OracleType.NVarChar).Value = dwData["SYBTYP"].ToString(); 
          or1.Parameters.Add("SYBKL1", OracleType.NVarChar).Value = dwData["SYBKL1"].ToString(); 
          or1.Parameters.Add("SYBKL2", OracleType.NVarChar).Value = dwData["SYBKL2"].ToString(); 
          or1.Parameters.Add("SYBKL3", OracleType.NVarChar).Value = dwData["SYBKL3"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS1", OracleType.NVarChar).Value = dwData["SYBANSTOSS1"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS2", OracleType.NVarChar).Value = dwData["SYBANSTOSS2"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS3", OracleType.NVarChar).Value = dwData["SYBANSTOSS3"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS4", OracleType.NVarChar).Value = dwData["SYBANSTOSS4"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS5", OracleType.NVarChar).Value = dwData["SYBANSTOSS5"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS6", OracleType.NVarChar).Value = dwData["SYBANSTOSS6"].ToString(); 
          or1.Parameters.Add("SYBANSTOSS7", OracleType.NVarChar).Value = dwData["SYBANSTOSS7"].ToString(); 
          or1.Parameters.Add("SYBSA", OracleType.NVarChar).Value = dwData["SYBSA"].ToString(); 
          or1.Parameters.Add("SYBUKGRD", OracleType.NVarChar).Value = dwData["SYBUKGRD"].ToString(); 
          or1.Parameters.Add("SYBLEITWEG", OracleType.NVarChar).Value = dwData["SYBLEITWEG"].ToString(); 
          or1.Parameters.Add("SYBBEM", OracleType.NVarChar).Value = dwData["SYBBEM"].ToString(); 
          or1.Parameters.Add("SYBSANR", OracleType.NVarChar).Value = dwData["SYBSANR"].ToString(); 
          or1.Parameters.Add("SYBCMD", OracleType.NVarChar).Value = dwData["SYBCMD"].ToString(); 
          or1.Parameters.Add("SYBFILLER", OracleType.NVarChar).Value = dwData["SYBFILLER"].ToString(); 
          or1.Parameters.Add("SYBAENZL", OracleType.NVarChar).Value = dwData["SYBAENZL"].ToString(); 
          or1.Parameters.Add("SYBAENDBEN", OracleType.NVarChar).Value = dwData["SYBAENDBEN"].ToString(); 
          or1.Parameters.Add("SYBAENDDAT", OracleType.NVarChar).Value = dwData["SYBAENDDAT"].ToString(); 
          or1.Parameters.Add("SYBNEUBEN", OracleType.NVarChar).Value = dwData["SYBNEUBEN"].ToString(); 
          or1.Parameters.Add("SYBNEUDAT", OracleType.NVarChar).Value = dwData["SYBNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
